const init = {
  messageNumber:{
    attentionNumber:0,
    likeAndCollectionNumber:0,
    reviewNumber:0,
    totalNumber:0
 } 
};

export default function message(state = init, action) {
  let newState = { ...state };
  const { type, payload } = action;
  switch (type) {
    case "addMessage":
      return {
        messageNumber: payload
      }
    case "updateSum":
      return {
        messageNumber: {
          ...state.messageNumber,
          totalNumber: state.messageNumber.totalNumber - state.messageNumber.reviewNumber,
          reviewNumber: 0
        }
      };
    case "reviewNumber":
      return {
        messageNumber: {
          ...state.messageNumber,
          reviewNumber: state.messageNumber.reviewNumber + 1,
          totalNumber: state.messageNumber.totalNumber + 1
        }
      };
    case "likeAndCollectionNumber":
      return {
        messageNumber: {
          ...state.messageNumber,
          likeAndCollectionNumber: state.messageNumber.likeAndCollectionNumber + 1,
          totalNumber: state.messageNumber.totalNumber + 1
        }
      };
    case "attentionNumber":
      return {
        messageNumber: {
          ...state.messageNumber,
          attentionNumber: state.messageNumber.attentionNumber + 1,
          totalNumber: state.messageNumber.totalNumber + 1
        }
      };
      break;
    default:
      return state;
  }
}